<?php
/**
*
* @package Board3 Portal v2 - Gallery (Addon)
* @copyright (c) Christian_N ( www.phpbb-projekt.de )
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

/**
* @package Gallery
*/
class portal_gallery_module
{
	/**
	* Allowed columns: Just sum up your options (Exp: left + right = 10)
	* top		1
	* left		2
	* center	4
	* right		8
	* bottom	16
	*/
	public $columns = 31;

	/**
	* Default modulename
	*/
	public $name = 'GALLERY';

	/**
	* Default module-image:
	* file must be in "{T_THEME_PATH}/images/portal/"
	*/
	public $image_src = 'portal_gallery.png';

	/**
	* module-language file
	* file must be in "language/{$user->lang}/mods/portal/"
	*/
	public $language = 'portal_gallery_module';

	/**
	* hide module name in ACP configuration page
	*/
	public $hide_name = true;

	
	
	public function get_template_center($module_id)
	{
		global $config, $template, $gallery_root_path, $phpEx, $phpbb_root_path;

		$gallery_root_path = GALLERY_ROOT_PATH;
		if (!function_exists('recent_gallery_images'))
		{
			include($phpbb_root_path . $gallery_root_path . 'includes/functions_recent.' . $phpEx);
		}
		$ints = array(
			'rows'		=> $config['board3_gallery_' . $module_id . '_rows'],
			'columns'	=> $config['board3_gallery_' . $module_id . '_columns'],
		);
		if ($config['board3_gallery_' . $module_id . '_mode'])
		{
			recent_gallery_images($ints, $config['board3_gallery_' . $module_id . '_display'], $config['board3_gallery_' . $module_id . '_mode']);
		}
		return 'gallery_center.html';
	}

	public function get_template_side($module_id)
	{
		global $config, $template, $gallery_root_path, $phpEx, $phpbb_root_path;

		$gallery_root_path = GALLERY_ROOT_PATH;
		if (!function_exists('recent_gallery_images'))
		{
			include($phpbb_root_path . $gallery_root_path . 'includes/functions_recent.' . $phpEx);
		}
		$ints = array(
			'rows'		=> $config['board3_gallery_' . $module_id . '_rows'],
			'columns'	=> $config['board3_gallery_' . $module_id . '_columns'],
		);
		if ($config['board3_gallery_' . $module_id . '_mode'])
		{
			recent_gallery_images($ints, $config['board3_gallery_' . $module_id . '_display'], $config['board3_gallery_' . $module_id . '_mode']);
		}
		return 'gallery_side.html';
	}

	public function get_template_acp($module_id)
	{	
		global $user, $gallery_root_path, $phpEx, $phpbb_root_path;

		$gallery_root_path = GALLERY_ROOT_PATH;
		include($phpbb_root_path . $gallery_root_path . 'includes/constants.' . $phpEx);
		$user->add_lang('mods/gallery_acp');
		return array(
			'title'	=> 'ACP_PORTAL_GALLERY_SETTINGS',
			'vars'	=> array(
				'legend1'								=> 'ACP_PORTAL_GALLERY_SETTINGS',
				'board3_gallery_' . $module_id . '_mode'			=> array('lang' => 'RRC_GINDEX_MODE',		'validate' => 'int',	'type' => 'custom',			'explain' => true,	'method' => 'rrc_modes', 'submit' => 'gallery_modes'),
				'board3_gallery_' . $module_id . '_rows'			=> array('lang' => 'RRC_GINDEX_ROWS',		'validate' => 'int',	'type' => 'text:7:3',		'explain' => false),
				'board3_gallery_' . $module_id . '_columns'			=> array('lang' => 'RRC_GINDEX_COLUMNS',	'validate' => 'int',	'type' => 'text:7:3',		'explain' => false),
				'board3_gallery_' . $module_id . '_display'			=> array('lang' => 'RRC_DISPLAY_OPTIONS',	'validate' => '',		'type' => 'custom',			'explain' => false,	'method' => 'rrc_display', 'submit' => 'gallery_display'),
			),
		);
	}

	/**
	* API functions
	*/
	public function install($module_id)
	{
		set_config('board3_gallery_' . $module_id . '_mode', '1');
		set_config('board3_gallery_' . $module_id . '_display', '60');
		set_config('board3_gallery_' . $module_id . '_rows', '1');
		set_config('board3_gallery_' . $module_id . '_columns', '1');
		return true;
	}

	public function uninstall($module_id)
	{
		global $db;

		$del_config = array(
			'board3_gallery_' . $module_id . '_mode',
			'board3_gallery_' . $module_id . '_display',
			'board3_gallery_' . $module_id . '_rows',
			'board3_gallery_' . $module_id . '_colums',
		);
		$sql = 'DELETE FROM ' . CONFIG_TABLE . '
			WHERE ' . $db->sql_in_set('config_name', $del_config);
		return $db->sql_query($sql);
	}

	public function rrc_modes($value, $key)
	{
		global $user;

		$rrc_mode_options = '';

		$rrc_mode_options .= '<option' . (($value & RRC_MODE_RECENT) ? ' selected="selected"' : '') . " value='" . RRC_MODE_RECENT . "'>" . $user->lang['RRC_MODE_RECENT'] . '</option>';
		$rrc_mode_options .= '<option' . (($value & RRC_MODE_RANDOM) ? ' selected="selected"' : '') . " value='" . RRC_MODE_RANDOM . "'>" . $user->lang['RRC_MODE_RANDOM'] . '</option>';

		// Cheating is an evil-thing, but most times it's successful, that's why it is used.
		return '<input type="hidden" name="config[' . $key . ']" value="' . $value . '" /><select name="' . $key . '[]" multiple="multiple" id="' . $key . '">' . $rrc_mode_options . '</select>';
	}
		
	public function gallery_modes($key, $module_id)
	{
		global $db, $cache;
			
		// Get selected extensions
		$values = request_var($key, array(0 => ''));
		
		$rrc_mode_options = array_sum($values);
		
		set_config($key, $rrc_mode_options);
	}

	public function rrc_display($value, $key)
	{
		global $user;

		$rrc_display_options = '';

		$rrc_display_options .= '<option value="' . RRC_DISPLAY_NONE . '">' . $user->lang['RRC_DISPLAY_NONE'] . '</option>';
		$rrc_display_options .= '<option' . (($value & RRC_DISPLAY_ALBUMNAME) ? ' selected="selected"' : '') . " value='" . RRC_DISPLAY_ALBUMNAME . "'>" . $user->lang['RRC_DISPLAY_ALBUMNAME'] . '</option>';
		$rrc_display_options .= '<option' . (($value & RRC_DISPLAY_COMMENTS) ? ' selected="selected"' : '') . " value='" . RRC_DISPLAY_COMMENTS . "'>" . $user->lang['RRC_DISPLAY_COMMENTS'] . '</option>';
		$rrc_display_options .= '<option' . (($value & RRC_DISPLAY_IMAGENAME) ? ' selected="selected"' : '') . " value='" . RRC_DISPLAY_IMAGENAME . "'>" . $user->lang['RRC_DISPLAY_IMAGENAME'] . '</option>';
		$rrc_display_options .= '<option' . (($value & RRC_DISPLAY_IMAGETIME) ? ' selected="selected"' : '') . " value='" . RRC_DISPLAY_IMAGETIME . "'>" . $user->lang['RRC_DISPLAY_IMAGETIME'] . '</option>';
		$rrc_display_options .= '<option' . (($value & RRC_DISPLAY_IMAGEVIEWS) ? ' selected="selected"' : '') . " value='" . RRC_DISPLAY_IMAGEVIEWS . "'>" . $user->lang['RRC_DISPLAY_IMAGEVIEWS'] . '</option>';
		$rrc_display_options .= '<option' . (($value & RRC_DISPLAY_USERNAME) ? ' selected="selected"' : '') . " value='" . RRC_DISPLAY_USERNAME . "'>" . $user->lang['RRC_DISPLAY_USERNAME'] . '</option>';
		$rrc_display_options .= '<option' . (($value & RRC_DISPLAY_RATINGS) ? ' selected="selected"' : '') . " value='" . RRC_DISPLAY_RATINGS . "'>" . $user->lang['RRC_DISPLAY_RATINGS'] . '</option>';

		// Cheating is an evil-thing, but most times it's successful, that's why it is used.
		return '<input type="hidden" name="config[' . $key . ']" value="' . $value . '" /><select name="' . $key . '[]" multiple="multiple" id="' . $key . '">' . $rrc_display_options . '</select>';
	}

	public function gallery_display($key, $module_id)
	{
		global $db, $cache;
			
		// Get selected extensions
		$values = request_var($key, array(0 => ''));
			
		$rrc_display_options = array_sum($values);
			
		set_config($key, $rrc_display_options);
	}
}

?>